package io.rong.imkit.webview

import android.graphics.Bitmap
import android.net.http.SslError
import android.os.Message
import android.view.KeyEvent
import android.webkit.HttpAuthHandler
import android.webkit.SslErrorHandler
import android.webkit.WebResourceResponse
import android.webkit.WebView

abstract class WebViewClientListener {
    open fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
        return false
    }

    open fun onReceivedError(
        view: WebView?,
        errorCode: Int,
        description: String?,
        failingUrl: String?
    ) {
    }

    open fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {}
    open fun onPageFinished(view: WebView?, url: String?) {}
    open fun onLoadResource(view: WebView?, url: String?) {}
    open fun shouldInterceptRequest(view: WebView?, url: String?): WebResourceResponse? {
        return null
    }

    open fun onTooManyRedirects(
        view: WebView?,
        cancelMsg: Message?,
        continueMsg: Message?
    ) {
    }

    open fun onFormResubmission(
        view: WebView?,
        dontResend: Message?,
        resend: Message?
    ) {
    }

    open fun doUpdateVisitedHistory(
        view: WebView?,
        url: String?,
        isReload: Boolean
    ) {
    }

    open fun onReceivedSslError(view: WebView?, handler: SslErrorHandler?, error: SslError?) {}
    open fun onReceivedHttpAuthRequest(
        view: WebView?,
        handler: HttpAuthHandler?,
        host: String?,
        realm: String?
    ) {
    }

    open fun shouldOverrideKeyEvent(view: WebView?, event: KeyEvent?): Boolean {
        return false
    }

    open fun onUnhandledKeyEvent(view: WebView?, event: KeyEvent?) {}
    open fun onScaleChanged(view: WebView?, oldScale: Float, newScale: Float) {}
    open fun onReceivedLoginRequest(
        view: WebView?,
        realm: String?,
        account: String?,
        args: String?
    ) {
    }
}